﻿using LD.BC;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace LD.Tool
{
    public partial class ToolIOSetFrm : FrmToolBaseSkip
    {
        public ToolIOSetFrm()
        {
            InitializeComponent();
            this.Shown += ToolMoveFrm_Shown;
            this.btn_ok.Click += Btn_ok_Click;
        }

        private void Btn_ok_Click(object sender, EventArgs e)
        {
            if (this.cob_io.SelectedIndex >= 0)
            {
                IoSet ioset = new IoSet()
                {
                    IoName = this.cob_io.Text,
                    Low_Hig = this.cob_lowHig.SelectedIndex,
                };
                this.TB_Tool.Param = Newtonsoft.Json.JsonConvert.SerializeObject(ioset);
            }
        }

        private void ToolMoveFrm_Shown(object sender, EventArgs e)
        {
            Init();
        }
        private void Init()
        {
            var ioList = BcFactory.Instance.Config.IoList.Where(p => p.IoType == 1).ToList();
            foreach (var item in ioList)
            {
                this.cob_io.Items.Add(item.Name);
            }

            if (this.TB_Tool.Param == null)
                return;
            var tool = Newtonsoft.Json.JsonConvert.DeserializeObject<IoSet>(this.TB_Tool.Param);
            if (tool != null)
            {
                this.cob_io.Text = tool.IoName + "";
                this.cob_lowHig.SelectedIndex = tool.Low_Hig;
            }
        }
    }
}
